package com.ea.eadp.nexus.test.common;

import java.util.Random;

/**
 * Created by ChuanYe on 7/25/2014.
 */
public enum Scope {
    BASIC_DOMAINDATA("basic.domaindata",0),
    BASIC_IDENTITY("basic.identity",1),
    BASIC_IDENTITY_WRITE("basic.identity.write",2),
    BASIC_PERSONA_WRITE("basic.persona.write",3),
    BASIC_PERSONA("basic.persona",4),
    BASIC_ENTITLEMENT_WRITE("basic.entitlement.write",5),
    BASIC_ENTITLEMENT("basic.entitlement",6),
    BASIC_ENCRYPTED_TOKEN("basic.encrypted_token",7),
    BASIC_ADMIN("basic.admin",8),
    BASIC_UTILITY("basic.utility",9),
    BASIC_COMMERCE("basic.commerce",10),
    BASIC_COMMERCE_WRITE("basic.commerce.write",11),
    BASIC_BILLING("basic.billing",12),
    BASIC_BILLING_WRITE("basic.billing.write",13),
    BULK_IDENTITY("bulk.identity", 14),
    BASIC_XBLTOKEN("basic.xbltoken", 15),
    BASIC_TWOFACTOR("basic.twofactor", 16),
    BASIC_MIGRATION_RECORD("basic.migration.record", 17),
    SERVER_SEARCH_IDENTITY("server.search.identity", 18),
    IDENTITY_MULTI_SEARCH("identity.multi.search", 19),
    BASIC_RESON("basic.reson", 20),
    BASIC_COMMERCE_CONSOLE("basic.commerce.console", 21),
    BASIC_COMMERCE_CONSOLE_WRITE("basic.commerce.console.write", 22),
    BASIC_PSNTOKEN("basic.psntoken", 23),
    CUSTOMIZEDLOG_READ("customizedlog.read", 24),
    BASIC_PRIVILEGE("basic.privilege", 25),
    BASIC_ANTELOPE_LINKS_BULK("basic.antelope.links.bulk", 26),
    BASIC_SCOI("basic.scoi", 27);

    private String name;
    private int index;

    private static Random random = new Random();

    private Scope(String name, int index) {
        this.name = name;
        this.index = index;
    }

    public static Scope getInvalidScope(Scope validScope) throws Exception {
        //int index = (validScope.getIndex() + random.nextInt(Scope.values().length - 1) + 1) % Scope.values().length;
        int index = validScope.getIndex() > 0 ? 0 : 1;
        return getScope(index);
    }

    public static Scope getScope(int index) throws Exception {
        for(Scope s:Scope.values()){
            if (s.getIndex() == index) return s;
        }
        throw new Exception("scopes not contain index " + index);
    }

    public String getName() {
        return name;
    }

    public int getIndex(){
        return index;
    }
}
